package com.zhuzi.guicollect.utils;

import com.github.plushaze.traynotification.animations.Animations;
import com.github.plushaze.traynotification.notification.Notification;
import com.github.plushaze.traynotification.notification.TrayNotification;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.control.Alert;
import javafx.util.Duration;
import org.controlsfx.control.Notifications;
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid;
import org.kordamp.ikonli.javafx.FontIcon;


/**
 * @author MI
 * @ClassName AlertUtils.java
 * @createTime 2021年10月27日 15:52:00
 */
public class AlertUtils {
    public static void showAlter(Alert.AlertType type, String content) {
        Platform.runLater(() -> {
            Alert alert = new Alert(type);
            alert.setTitle("提示信息");
            alert.setHeaderText(content);
            alert.setContentText(content);
            alert.showAndWait();
        });
    }

    /**
     * 提示消息
     *
     * @param title    标题
     * @param text     内容
     * @param showTime 显示几秒
     * @param pos      显示位置
     */
    public static void showNotifications(String title, String text, int showTime, Pos pos) {
        showNotifications(title, text, showTime, pos, false);
    }

    public static void showNotifications(String title, String text, int showTime, Pos pos, boolean darkStyle) {
        //图标查询地址 https://fa5.dashgame.com/#/%E5%9B%BE%E6%A0%87
        FontIcon warnIcon = new FontIcon(FontAwesomeSolid.GRIN_BEAM);
        // warnIcon.getStyleClass().add("error");
        warnIcon.setIconSize(25);
        //十进制颜色
        String webColor = "#" + Integer.toHexString(5470085).substring(0, 6).toUpperCase();
        // warnIcon.setFill(Color.valueOf("#8CD3EC"));
        Notifications notificationBuilder = Notifications.create()
                .title(title)
                .text(text)
                .graphic(warnIcon)
                .hideAfter(Duration.seconds(showTime))
                .position(pos)

                .onAction(e -> System.out.println("Notification clicked on!"));
        // .threshold((int) thresholdSlider.getValue(),
        //         Notifications.create().title("Threshold Notification"));
        if (darkStyle) {
            notificationBuilder.darkStyle();
            FontIcon warnIconCry = new FontIcon(FontAwesomeSolid.SAD_CRY);
            notificationBuilder.graphic(warnIconCry);
        }
        //必须这样通知
        Platform.runLater(() -> {
            notificationBuilder.show();
        });
    }

    /**
     * 新的通知
     */
    public static void showJfxNote() {
        // FontAwesomeIconView icon = new FontAwesomeIconView(FontAwesomeIcon.GLASS);
       /* JFXSimpleNotificationTemplate template = new JFXSimpleNotificationTemplate(); // Template Class
        FontAwesomeIconView icon = new FontAwesomeIconView(FontAwesomeIcon.GLASS);
        template.setHeader(icon, "Fast Food");
        template.setBody("Lily (MacDonald)", "Su pedido esta listo, solo debe recogerlo en el lugar mas solicitado");
        JFXButton aceptar = new JFXButton("Responder");
        template.setActions(aceptar);
        JFXNotifications.create().position(pos)
                .hideAfter(Duration.seconds(6))
                .template(template)
                .showMessage();*/

    }

    public static void showTrayNotification(String title, String message, int second) {
        Platform.runLater(() -> {
            Notification notification = com.github.plushaze.traynotification.notification.Notifications.SUCCESS;
            TrayNotification tray = new TrayNotification();
            tray.setTitle(title);
            tray.setMessage(message);
            tray.setNotification(notification);
            tray.setAnimation(Animations.POPUP);
            tray.showAndDismiss(Duration.seconds(second));
        });
    }
}
